#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> nextGreaterElements(vector<int>& nums) {
        int n=nums.size();
        int tag=0;
        vector<int>stk;vector<int>ans(2*n-1);
        for(int i=2*n-1;i>=0;i--)
        {
            tag=i%n;
            while(!stk.empty()&&stk.back()<=nums[tag])
            {
                stk.pop_back();
            }
            if(!stk.empty())
            {
                ans[tag]=stk.back();
            }
            else {
                ans[tag]=-1;
            }
            stk.push_back(nums[tag]);
        }
        return ans;
    }
};